(function(window, document) {
    angular
        .module('app')
        .factory('payOnedayFactory', payOnedayFactory);

    payOnedayFactory.$inject = ['$http', '$q'];

    function payOnedayFactory ($http, $q) {
        var service = {};
        var baseUrl = 'http://www.vipbanlv.com/api/';
        var _uid = ''; // 用户唯一标识
        var _dayid = 0; // 帐号天数唯一标识

        service.setUid = function(uid) {
            _uid = uid;
        };

        service.setDayid = function(dayid) {
            _dayid = dayid;
        };

        // 购买账号
        service.payOnedayPromise = function(accountid) {
            var deferred = $q.defer();
            $http({
                method: 'GET',
                url: baseUrl,
                params: {
                    m: 'pay',
                    a: 'oneday',
                    uid: _uid,
                    dayid: _dayid
                }
            }).success(function(res) {
                deferred.resolve(res);
            }).error(function() {
                deferred.reject('购买帐号请求出错');
            });

            return deferred.promise;
        };

        // 返回service 对象
        return service;
    }
})(window, document);
